<%--
  User: Sujan
  Date: Apr 30, 2007
  Time: 4:40:25 PM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.users.Functionality" %>
<%@ page import="com.scalar.chiptrack.users.User" %>
<%@ page import="java.io.IOException" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/creditNoteAction.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
    var lineItemsCount = 0;
    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }
            
    function reset()
    {
        document.creditNoteForm.reset();
    }
    function submitPage()
    {
        var form =  document.creditNoteForm;
       /* var pa = document.getElementById( "errors" );
        pa.innerHTML = "";*/
        enableFormFields();
        form.action = "<%=chipTracContext%>/creditNoteAction.do?action=confirmApprove"
        form.submit();
    }
    function enableFormFields()
    {
        var form = document.creditNoteForm;
        for (var k = 0; k < lineItemsCount; k++)
        {
            //form['lineItems[' + k + '].marketingHold'].disabled = false;
            form['lineItems[' + k + '].financeHold'].disabled = false;
            /*form['lineItems[' + k + '].operationsHold'].disabled = false;
            form['lineItems[' + k + '].salesHold'].disabled = false;*/
        }
    }
</SCRIPT>

<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
	    <!-- Side Navigation start -->
	    <%@include file="/jsp/finance/finance_menu.jsp" %>
	    <!-- end of the side navigations -->
        </TD>
	    <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	    <TD valign="top" width="100%"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	    <BR>
        <html:form action="/creditNoteAction.do" name="creditNoteForm" type="com.scalar.chiptrack.finance.creditNote.forms.CreditNoteForm" onsubmit="return false;">
        <nested:hidden property="noteType"/>
        <nested:hidden property="creditNoteId"/>
        <%
            String action = request.getParameter ( "action" );
        %>
            <TABLE width="95%" align="right" cellpadding="2" cellspacing="2" border="0">
			    <TR><TD colspan="5" class="NArialW" align="center">
                    <logic:equal value="Credit" name="creditNoteForm" property="noteType">
                       Approve Credit Note
                    </logic:equal>
                    <logic:notEqual value="Credit" name="creditNoteForm" property="noteType">
                       Approve Debit Note 
                    </logic:notEqual>
                </TD></TR>
                <TR><TD colspan='5' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></TD></TR>
			    <TR><TD colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"/></TD></TR>
			    <TR><TD colspan='5' class="NArialL"><chiptrack:info styleClass="NArialL"/></TD></TR>
			    <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                <tr>
                    <td class="NArialL">
                    <logic:equal value="Credit" name="creditNoteForm" property="noteType">
                        Credit Note #:
                    </logic:equal>
                    <logic:notEqual value="Credit" name="creditNoteForm" property="noteType">
                        Debit Note #:
                    </logic:notEqual>

                    </td>
                    <td class="NArialL">
                        <nested:write property="creditNoteNumber" />
                        <nested:hidden property="creditNoteNumber" />
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL">
                        Date Issued:
                    </td>
                    <td class="bodytext">
                        <nested:write property="issueDate" />
                        <nested:hidden property="issueDate" />
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        Customer:
                    </td>
                    <td class="bodytext">
                        <nested:write property="customerName" />
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL">
                        Sales Order No:
                    </td>
                    <td class="bodytext">
                        <nested:write property="salesOrderNo" />
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        Customer PO No:
                    </td>
                    <td class="bodytext">
                        <nested:write property="customerPONo" />
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL">
                        Sales Rep:
                    </td>
                    <td class="bodytext">
                        <nested:write property="salesRep" />
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        End Customer:
                    </td>
                    <td class="bodytext">
                        <nested:write property="endCustomerName" />
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL">
                        End User:
                    </td>
                    <td class="bodytext">
                        <nested:write property="endUserName" />
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        Pay Terms:
                    </td>
                    <td class="bodytext">
                        <nested:write property="payTerms" />
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL">
                       Packing Slip Label:
                    </td>
                    <td class="bodytext">
                       <bean:write name="creditNoteForm" property="packingSlipLabel" />
                    </td>
                </tr>
                <tr>
                    <td class="NArialL" valign="top">
                        Billing Address:
                    </td>
                    <td class="bodytext" valign="top">
                        <nested:write property="billingAddressAsHTML" filter="false"/>
                    </td>
                    <td>&nbsp;</td>
                    <td class="NArialL" valign="top">
                       Shipping Address:
                    </td>
                    <td class="bodytext" valign="top">
                       <nested:write property="shippingAddressAsHTML" filter="false"/>
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">Consider Units:</td>
                    <td class="bodytext" valign="top">
                        <nested:equal property="isUnits" value="true">Yes</nested:equal>
                        <nested:notEqual property="isUnits" value="true">No</nested:notEqual>
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">Comments:</td>
                    <td  colspan="5">
                        <nested:textarea property="comments" rows="4" cols="90" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.creditNoteForm.comments,300)" onkeyup="javascript:setTextAreaMaxLength(document.creditNoteForm.comments,300)"/>
                    </td>
                </tr>
                <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                
                <tr>
                    <td colspan=5>
                        <table border="0" width="100%">
	                        <tr>
                                <td rowspan="2" width="8%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Line Item #</font></td>
	                            <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">PO Line Item #</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.mfgPartNumber" /></font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.customerPartNumber"/></font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Description</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Shipped Qty</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Ship Date</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Unit Price</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Amount</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Reason</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Change To Qty</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Change To Price</font></td>
                                <td rowspan="2" width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Change To Amount</font></td>
                                <td rowspan="2" <%--colspan="4"--%> width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Fin Hold</font></td>
                            </tr>
                            <tr>
                                <%--<td align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Mktg</font></td>
                                <td align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Fin</font></td>
                                <td align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Ops</font></td>
                                <td align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Sales</font></td>--%>
                            </tr>
                            
                            <nested:iterate property="lineItems" indexId="idx" id="lineItem">
                            <tr>
                                <nested:hidden property="lineItemId"/>
                                <nested:hidden property="isCreditNote" />
                                <td width="8%" bgcolor="#DEE1E2" align=center class="NArialL"> <nested:write property="lineItemNo" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="poLineItemNo" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="manufacturingPartNo" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="customerPartNo" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="lineItemDescription" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="shippedQtyAsString" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="shippedDate" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="unitPriceAsString" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:write property="amountAsString" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL"><nested:text property="reason" size="15" styleClass="txfield" readonly="true" /></td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL">
                                    <nested:write property="adjustmentQtyAsString" />
                                </td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL" nowrap>
                                    <nested:write property="discountPriceAsString" />
                                </td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL" nowrap>
                                    <nested:write property="discountAmountAsString"/>
                                </td>
                                <%--<td width="10%" bgcolor="#DEE1E2" align=center class="NArialL">
                                    <% if (user.isActionAllowed(Functionality.MARKETING_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                                        <nested:select property="marketingHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } else { %>
                                        <nested:select property="marketingHold" styleClass="txfield" disabled="true">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } %>
                                </td>--%>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL">
                                    <% if (user.isActionAllowed(Functionality.APPROVE_CREDIT_DEBIT_NOTE, User.USER_ACTION_MODIFY)) { %>
                                        <nested:select property="financeHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } else { %>
                                        <nested:select property="financeHold" styleClass="txfield" disabled="true">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } %>
                                </td>
                                <%--<td width="10%" bgcolor="#DEE1E2" align=center class="NArialL">
                                    <% if (user.isActionAllowed(Functionality.OPERATIONS_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                                        <nested:select property="operationsHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                     <% } else { %>
                                        <nested:select property="operationsHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } %>

                                </td>
                                <td width="10%" bgcolor="#DEE1E2" align=center class="NArialL">
                                    <% if (user.isActionAllowed(Functionality.SALES_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                                        <nested:select property="salesHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } else { %>
                                        <nested:select property="salesHold" styleClass="txfield">
                                            <html:option value=""></html:option>
                                            <html:option value="0">X</html:option>
                                        </nested:select>
                                    <% } %>
                                </td>--%>
                            </tr>
                            </nested:iterate>
                            <nested:size id="lineItemsCount" property="lineItems"/>
                            <script type="text/javascript">
                                lineItemsCount = <%=lineItemsCount.intValue()%>;
                            </script>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td colspan="5" align="center">
                        <a href="javascript:submitPage()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Approve Credit/Debit Note';return true" onmouseout="window.status='';return true" title="Click here to Approve Credit/Debit Note" alt=""></a>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
                    </td>
			    </tr>
			    <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='20'></TD></TR>
		    </TABLE>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>